<?php

namespace Desktopd\MUA;


// MIME header encoding (B, Q)
class MIMEHeaderEncoding extends Encoding {
    public static function encode ($plain) {
        return new self(mb_encode_mimeheader("$plain", 'UTF-8'));
    }
    
    public function decode () {
        $decoded = mb_decode_mimeheader($this->getEncoded());
        if ('UTF-8' !== ($charset = strtoupper(mb_internal_encoding()))) {
            $decoded = mb_convert_encoding($decoded, 'UTF-8', $charset);
        }
        
        return $decoded;
    }
}


// vim: ts=4 et ai

